package com.yunkeji.admin.controller.call;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.CallLogVo;
import com.yunkeji.system.domain.bo.CallLogBo;
import com.yunkeji.system.service.ICallLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 通话日志
 *
 * @author zhang
 * @date 2024-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/callLog")
public class CallLogController extends BaseController {

    private final ICallLogService iCallLogService;

    /** 查询通话日志列表 */
    @SaCheckPermission("system:callLog:list")
    @GetMapping("/list")
    public TableDataInfo<CallLogVo> list(CallLogBo bo, PageQuery pageQuery) {
        return iCallLogService.queryPageList(bo, pageQuery);
    }

    /** 导出通话日志列表 */
    @SaCheckPermission("system:callLog:export")
    @Log(title = "通话日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CallLogBo bo, HttpServletResponse response) {
        List<CallLogVo> list = iCallLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "通话日志", CallLogVo.class, response);
    }

    /**
     * 获取通话日志详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:callLog:query")
    @GetMapping("/{id}")
    public R<CallLogVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iCallLogService.queryById(id));
    }

    /** 新增通话日志 */
    @SaCheckPermission("system:callLog:add")
    @Log(title = "通话日志", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CallLogBo bo) {
        return toAjax(iCallLogService.insertByBo(bo));
    }

    /** 修改通话日志 */
    @SaCheckPermission("system:callLog:edit")
    @Log(title = "通话日志", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CallLogBo bo) {
        return toAjax(iCallLogService.updateByBo(bo));
    }

    /**
     * 删除通话日志
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:callLog:remove")
    @Log(title = "通话日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iCallLogService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
